package com.application.chiettinhdienluc.utils;

import java.util.ArrayList;
import java.util.List;

import com.application.chiettinhdienluc.data.GlobalData;
import com.application.chiettinhdienluc.model.ChietTinhModel;
import com.application.chiettinhdienluc.model.NhanCongChiTietModel;
import com.application.chiettinhdienluc.model.VatTuChiTietModel;
import com.application.chiettinhdienluc.ui.MainTabFragmentActivity;


public class CalculationUtils {
	
	
	public static double calculateChiPhiVatTu(List<VatTuChiTietModel> vattuList)
	{
		double chiphiVatTu = 0;
		for(int i =0; i <vattuList.size(); i++ ) {
			VatTuChiTietModel vtct = vattuList.get(i);
			chiphiVatTu = chiphiVatTu + vtct.getSoLuong()*vtct.getDonGia();			
		}	
		
		return chiphiVatTu;
	}
	

	
	public static double calculateChiPhiNhanCong(List<NhanCongChiTietModel> nhancongList)
	{
		double chiphiNhanCong = 0;
		for(int i =0; i <nhancongList.size(); i++ ) {
			NhanCongChiTietModel ncct = nhancongList.get(i);
			chiphiNhanCong = chiphiNhanCong + ncct.getKhoiLuong()*ncct.getDongia();			
		}	
		
		return chiphiNhanCong;
	}
	
	public static void calculate(ChietTinhModel ct , double cp_vatlieu , double cp_nhancong){
		
		String dvdt = ct.get_DonViDauTu();
		
		double cp_ttk;
		double cp_tt;
				
		double cp_vc = ct.get_ChiPhiVC();
		double cp_vl = cp_vatlieu + cp_vc;
		
		double cp_nc = cp_nhancong;
		double cp_mm =ct.get_ChiPhiMM();
		
		double cp_c;
		double cp_tl;
		double cp_k;
		double tien_gtt;
		double tien_gtgt;
		double so_tien;
		double lam_tron;
			
		
		if(dvdt.equalsIgnoreCase("0")){			
			
			cp_nc = cp_nhancong;			
			cp_tt = cp_vl + cp_nc + cp_mm;
			
			cp_c = (double) (0.2*0.65*cp_nc);
			so_tien = cp_tt + cp_c;
			lam_tron = Math.round(so_tien/100) * 100;	
						
			
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiVL(cp_vl);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiVT(cp_vatlieu);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiNC(cp_nc);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiMM(cp_mm);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTT(cp_tt);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiC(cp_c);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_SoTien(so_tien);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_LamTron(lam_tron);	
			
			tien_gtgt = 0;			
			cp_k = 0;
			cp_ttk =0;
			cp_tl =0;
			tien_gtt =0;
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_TienGTGT(tien_gtgt);	
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiK(cp_k);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTTK(cp_ttk);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTL(cp_tl);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_TienGTT(tien_gtt);
			
		}
		else if(dvdt.equalsIgnoreCase("1")||dvdt.equalsIgnoreCase("3")){
				
			
			cp_mm = ct.get_ChiPhiMM();
			
			 
			cp_tt = cp_vl + cp_nc + cp_mm;
			
			cp_c = (double) (0.2*0.65*cp_nc);
			
			tien_gtt =  cp_tt + cp_c;
			tien_gtgt = (double) (0.1*tien_gtt);
			
			so_tien = tien_gtt + tien_gtgt;
			
			lam_tron = Math.round(so_tien/100) * 100;	
			
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiVL(cp_vl);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiVT(cp_vatlieu);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiNC(cp_nc);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiMM(cp_mm);
	
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTT(cp_tt);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiC(cp_c);
			//ct.set_TienGTT(tien_gtt);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_TienGTGT(tien_gtgt);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_SoTien(so_tien);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_LamTron(lam_tron);	
			
			cp_k = 0;
			cp_ttk =0;
			cp_tl =0;
			tien_gtt =0;
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiK(cp_k);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTTK(cp_ttk);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTL(cp_tl);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_TienGTT(tien_gtt);
			
		}
		else if ( dvdt.equalsIgnoreCase("2") ){
			cp_nc = cp_nhancong;
			cp_mm = ct.get_ChiPhiMM();
			
			
			cp_ttk = (double) (0.015*(cp_vl + cp_nc + cp_mm));
			cp_tt = cp_vl + cp_nc + cp_mm + cp_ttk;
			
			cp_c = (double) (0.65*cp_nc);
			
			cp_tl = (double) (0.06*(cp_tt + cp_c));
			cp_k = (double) (0.037*(cp_tt+ cp_c + cp_tl));
			
			tien_gtt =  cp_tt + cp_c +cp_tl + cp_k;
			
			tien_gtgt = (double) (0.1*tien_gtt);
			
			so_tien = tien_gtt + tien_gtgt;
			
			lam_tron = Math.round(so_tien/100) * 100;	
			
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiVL(cp_vl);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiVT(cp_vatlieu);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiNC(cp_nc);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiMM(cp_mm);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTTK(cp_ttk);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTT(cp_tt);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiC(cp_c);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiTL(cp_tl);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_ChiPhiK(cp_k);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_TienGTT(tien_gtt);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_TienGTGT(tien_gtgt);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_SoTien(so_tien);
			MainTabFragmentActivity.getInstance().getLocalChietTinhMain().set_LamTron(lam_tron);		
		}
	}


}
